#ifndef _HashCallBacker_H_
#define _HashCallBacker_H_
#include <iostream>
#include "Hash/SHA1.h"
#include "Hash/md5.h"
using namespace std;

class HashCallBacker{
public:
	virtual string hash(const string &str)=0;
};

class SHA1HashCallBacker:public HashCallBacker{
public:
	string hash(const string &str)override;
};

class MD5HashCallBacker:public HashCallBacker{
public:
	string hash(const string &str)override;
};

string SHA1HashCallBacker::hash(const string &str)
{
	SHA1 s1;
	string result=s1.sha1(str);
	return result;
}

string MD5HashCallBacker::hash(const string &str)
{
	int i;
	long hash = 0;
	const char *instr=str.c_str();
	ostringstream oss;
	unsigned char digest[16];
	md5_state_t md5state;
	md5_init(&md5state);
    	md5_append(&md5state, (const unsigned char *)instr, strlen(instr));
    	md5_finish(&md5state, digest);
    	for(i = 0; i < 4; i++)
    	{
    		hash += ((long)(digest[i*4 + 3]&0xFF) << 24)
    		| ((long)(digest[i*4 + 2]&0xFF) << 16)
    		| ((long)(digest[i*4 + 1]&0xFF) <<  8)
    		| ((long)(digest[i*4 + 0]&0xFF));
    	}
    	oss<<hash;
	return oss.str();
}


#endif